﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace WindowsFormsApplication1
{
    public partial class Form2 : Form
    {
        private string username;
        private string power;
        private DateTime logonTime;
        public void setUsername(string username)
        {
            this.username = username;
        }
        public void setPower(string power)
        {
            this.power = power;
        }
        public void setLogonTime(DateTime logonTime)
        {
            this.logonTime = logonTime;
        }
        public Form2()
        {
            InitializeComponent();
        }

        private void Form2_Load(object sender, EventArgs e)
        {
            toolStripStatusLabel2.Text = username;
            toolStripStatusLabel4.Text = returnPowerName(power.Trim());
            toolStripStatusLabel6.Text = logonTime.ToString();
            listView1.LargeImageList = imageList1;
            this.flushRoomImage();
        }
        private string returnPowerName(string power)
        {
            string returnPowerName = null;
            switch (power)
            {
                case "0": { returnPowerName = "数据库管理员"; }; break;
                case "1": { returnPowerName = "大堂经理"; }; break;
                case "2": { returnPowerName = "普通员工"; }; break;
            }
            return returnPowerName;
        }

        private void 数据库管理ToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void menuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {

        }

        private void flushRoomImage()
        {
            string sql = "SELECT * FROM tb_Room";
            SqlDataReader sdr = DatabaseHelper.GetSqlDataReader(sql);
            if (sdr.HasRows)
            {
                while (sdr.Read())
                { 
                    string zt = sdr["RoomZT"].ToString();
                    if(zt.Trim().Equals("待用"))
                    {
                        listView1.Items.Add(sdr["RoomName"].ToString(), 0);
                    }
                    else
                    {
                        listView1.Items.Add(sdr["RoomName"].ToString(), 1);
                    }
                }
            }
            sdr.Close();
        }
    }
}
